package com.api.shopapi.mapper;


import com.api.shopapi.entity.RobotPlace;
import com.api.shopapi.entity.Togwatch;
import com.api.shopapi.entity.views.TypesCall;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface TogwatchMapper {


    //查询上一个月报警的表数据
    @Select("select ProductModel,CreateTime,Lon,Lat,GaoYa,DiYa,Xinlv,Type from tog_watch_for_upload " +
            "where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 "+
            "and userId= #{userId} ")
    List<Togwatch> getTogwatch(@Param("userId") String userId );

    //查询报警手表的老人id
    @Select("select UserId from tog_watch_for_upload " +
            "where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 " +
            "group by userId")
    List<String> getUserId();

    //查询报警次数
    @Select("select count(*) from tog_watch_for_upload " +
            "where UserId = #{userId} and PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 ")
    int getStepsCount(@Param("userId") String userId);


    @Select("select CreateTime,Sos,Weilan,Type from tog_watch_for_upload " +
            "where UserId = #{userId} and PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 ")
    List<TypesCall> getTyps(String userId);


    //查询上个月机器人陪护下单的用户id
    @Select("select UserId from robot_for_upload " +
            "where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 " +
            "group by userId")
    List<String> getRobotUserId();


    //查询上一个月机器人下单表数据
    @Select("select * from robot_for_upload " +
            "where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( CreateTime, '%Y%m' ) ) =1 "+
            "and userId= #{userId} ")
    List<RobotPlace> getRobotPlace(String userId);
}
